<?php

class Silk_Zgb_Model_Attribute_Source_Warehouse extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
	public function getAllOptions($withEmpty = false)
	{
		if (is_null($this->_options)) {
            $this->_options = Mage::getModel('zgb/warehouse')->toOptionArray();
        }
        $options = $this->_options;

        $zgb = Mage::helper('zgb');
        $session = Mage::getSingleton('admin/session');
        $roleId = $session->getUser()->getRoleId();
        $user = $session->getUser();
        if($roleId == $zgb->getRoleId('warehouse'))
        {
            return $options;
        }
        array_unshift($options, array('value'=>'', 'label'=>Mage::helper('core')->__('-- Please Select --')));
        return $options;
	}

	/**
     * Get a text for option value
     *
     * @param string|integer $value
     * @return string
     */
    public function getOptionText($value)
    {
        $options = $this->getAllOptions(false);

        foreach ($options as $item) {
            if ($item['value'] == $value) {
                return $item['label'];
            }
        }
        return false;
    }

    /**
     * Convert to options array
     *
     * @return array
     */
    public function toOptionArray()
    {
        return $this->getAllOptions();
    }
}